package com.hfy.shop.mapper;

import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;

/**
 * @ author 韩
 * time: 2024/9/11 17:20
 */

@Mapper
public interface PayMapper {

    @Select("SELECT balance-#{salePrice} >= 0 FROM `balance` WHERE account = #{account}")
    Boolean checkBalance(@Param("account") Long account,@Param("salePrice") Integer salePrice);

    @Update("UPDATE `balance` SET balance = balance - #{salePrice} WHERE account = #{account}")
    void decreaseBalance(@Param("account") Long account,@Param("salePrice") Integer salePrice);

    @Insert("INSERT INTO `pay_log` (cost, pay_type, account, time, good_id) VALUES (#{cost}, #{payType}, #{account}, #{now}, #{goodId})")
    void logPay(@Param("cost") Integer cost, @Param("payType") Integer payType, @Param("account") Long account, @Param("now") LocalDateTime now, @Param("goodId") Integer goodId);
}
